<template>
  <div>
    <!-- 顶部导航栏 -->
    <van-sticky :offset-top="0">
      <van-nav-bar
        title="添加地址"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
      />
    </van-sticky>

    <van-address-edit
      :area-list="areaList"
      show-set-default
      show-search-result
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @change-detail="onChangeDetail"
    />
  </div>
</template>

<script>
import { Toast } from 'vant';
import {
  deleteAction,
  detailAction,
  listAction,
  saveAction,
  getListAction,
} from "@/api/my/index";
import areaList from "@/assets/area";
export default {
  data() {
    return {
      chosenAddressId: "1",
      searchResult: [],
      addresslist: [],
      areaList,
      act: "add",
      list: [],
      num: 118,
    };
  },

  methods: {
    //   保存收货地址
    onSave(content) {
      console.log(content);
      this.act = "add";
      saveAction({
        address: content.province + content.city + content.county,
        addressId: this.num + 1,
        checked: "false",
        detailadress: content.addressDetail,
        openId: localStorage.getItem("openId"),
        telNumber: content.tel,
        userName: content.name,
      }).then((res) => {
        console.log(res);
        if (res.data) {
          Toast({
            message: "添加成功",
            icon: "like-o",
          });
          this.$router.go(-1);
          this.num++;
        }
      });
    },
    // 添加收货地址
    onAdd() {
      console.log("新增");
      this.act = "none";
    },
    // 修改收货地址
    onEdit(item, index) {
      console.log("编辑", index);
    },
    onClickLeft() {
      this.$router.go(-1);
    },
    //切换默认收获地址
    onChangeDetail(value) {
      console.log(value);
    },
  },
};
</script>

<style scoped lang='less'>
</style>